#include "quadratics-core.h"
#include "quadratics-backend.h"
#include "quadratics-log.h"
#include <stdlib.h>

int compute(Coef *coef, Root *root){
	 
	double a  = coef-> a;
	double b  = coef-> b;
	double c  = coef-> c;
	double d; //determinate
	//double root1,root2; //roots
	char myString[128]; 
	//calculate determinate
	d = b * b - 4 * a * c;
	
	printf("A: %lf B: %lf C: %lf", a, b, c);

	sprintf(myString,"A: %lf B: %lf C: %lf", a, b, c);	
	printlog(myString);

	printf("\nDeterminate: %lf", d);
	
	
	sprintf(myString,"Determinate: %lf", d);
	printlog(myString);
	//printlog(d);
		
	//test to make sure result is not imaginary
	if(d >= 0){
		root -> x1 = (-b + calculateSqrt(d)) / (2 * a);
		root -> x2 = (-b - calculateSqrt(d)) / (2 * a);
		printf("\nFirst Root is %.8lf", root -> x1);
		
		sprintf(myString,"First Root is %.8lf", root -> x1);
		printlog(myString);
		
		printf("\nSecond Root is %.8lf\n", root -> x2);

		sprintf(myString,"Second Root is %.8lf\n", root -> x2);
		printlog(myString);
	} else {
		printf("\nRoots are imaginary\n");
		//printlog("\nRoots are imaginary\n");
	}
return 2;
		
}
double checkInput()
{
	char buffer[256];
	double input, n = 0;
	int check, goodNum = 0;
	
	fgets (buffer,256,stdin);
	
	//loops until we get a "string" of numbers, and numbers only.
	  while(atof(buffer) == 0)
	  {
		  printf("Please enter valid numbers only:");
		  //printlog("Please enter valid numbers only:");
		  fgets (buffer,256,stdin);
	  }
	  n = atof(buffer);
	
	return n;
	
}

